package com.jingsheng.jingshengcity.mvp.ui.activity.store;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerStoreComponent;
import com.jingsheng.jingshengcity.di.module.StoreModule;
import com.jingsheng.jingshengcity.mvp.contract.StoreContract;
import com.jingsheng.jingshengcity.mvp.presenter.StorePresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.StoreTabAdapter;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/8.
 */

public class StoreActivity extends BaseActivity<StorePresenter> implements StoreContract.View, View.OnClickListener {

    @NonNull
    @BindView(R.id.tab_layout)
    TabLayout mTabLayout;
    @NonNull
    @BindView(R.id.vp_fragment)
    ViewPager mViewPager;
    @NonNull
    @BindView(R.id.tv_store_detail)
    TextView mTvStoreDetail;

    private String mTabTitle[] = new String[]{"店铺首页", "全部商品", "最近上新", "促销活动"};

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerStoreComponent
                .builder()
                .appComponent(appComponent)
                .storeModule(new StoreModule(this)) //请将StoreActivityModule()第一个首字母改为小写
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        return R.layout.activity_store;
    }

    @Override
    public void initData() {
        StoreTabAdapter adapter = new StoreTabAdapter(getSupportFragmentManager(), mTabTitle);
        mViewPager.setAdapter(adapter);
        mViewPager.setOffscreenPageLimit(mTabTitle.length);
        mTabLayout.setupWithViewPager(mViewPager);

        initEvent();
    }

    private void initEvent() {
        mTvStoreDetail.setOnClickListener(this);
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_store_detail:
                toDetail();
                break;
        }
    }

    private void toDetail() {
        Intent intent = new Intent(this, StoreDetailActivity.class);
        startActivity(intent);
    }
}